package org.benxiong.iplay.model;

import org.benxiong.iplay.util.GlobalVar;
import org.benxiong.iplay.util.MeasurementUtil;
import org.benxiong.iplay.util.PathUtil;

import android.content.Context;
import android.content.SharedPreferences;

public class UserThumbnail {
	private String	username;
	private long	profilePictureVersion;
	private Double	latitude;
	private Double	longitude;
	private Long	lastUpdate;
	private String	info;
	private String	distanceToMe;

	public String getDistanceToMe() {
		// distance from GlobalVar .currentLat, .currentLng
		if (distanceToMe == null) {
			if (this.latitude != null && this.longitude != null) {
				// call miles or meters
				SharedPreferences sp = GlobalVar.appContext.getSharedPreferences("unit", Context.MODE_PRIVATE);
				boolean isEurop = sp.getBoolean("is_European", false);
				if (isEurop) {
					distanceToMe = MeasurementUtil.distanceMilesString(this.latitude, this.longitude, 
							GlobalVar.currentLocation.getLatitude(), GlobalVar.currentLocation.getLongitude());
				} else {
					distanceToMe = MeasurementUtil.distanceMeterssString(this.latitude, this.longitude, 
							GlobalVar.currentLocation.getLatitude(), GlobalVar.currentLocation.getLongitude());
				}
			}
		}
		return distanceToMe == null ? "" : distanceToMe;
	}

	public void setDistanceToMe(String distanceToMe) {
		this.distanceToMe = distanceToMe;
	}

	public String getThumbnailUrl() {
		return PathUtil.profilePictureUrl(this.getUsername(), this.getProfilePictureVersion());
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public long getProfilePictureVersion() {
		return profilePictureVersion;
	}

	public void setProfilePictureVersion(long profilePictureVersion) {
		this.profilePictureVersion = profilePictureVersion;
	}

	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public Long getLastUpdate() {
		return lastUpdate;
	}

	public void setLastUpdate(Long lastUpdate) {
		this.lastUpdate = lastUpdate;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

}
